Estoy trabajando para iniciar sesión con React JS y wordpress con el complemento JWT Authentication for WP REST API . Quisiera obtener token pero tengo un problema
El código está aquí:
//... function Login() { const[username, setUsername] = useState("") const[password, setPassword] = useState("") const access = async () => { const response = await fetch(`http://wp-playground.test/wp-json/jwt-auth/v1/token`, { method: 'POST', header: { 'Content-Type' : 'application/json', }, body : JSON.stringify({ username: username, password: password }) }) const data = await response.json() console.log(data) setUsername("") setPassword("") } return ( <div> <h2>Login</h2> <label>Username: </label><input value={username} onChange={(e) => setUsername(e.target.value)}/><br/><br/> <label>Password: </label><input type="password" value={password} onChange={(e) => setPassword(e.target.value)}/><br/><br/> <button onClick={access}>Login</button> </div> )y me sale asi:
{ code: "[jwt_auth] empty_username" data: { status: 403 } message: "<strong>Error</strong>: The username field is empty." }¡Gracias por tu atención!